//
//  ViewController.m
//  Model
//
//  Created by Eno-work on 2018/11/9.
//  Copyright © 2018 Eno-work. All rights reserved.
//

#import "ViewController.h"
#import "model.h"
#import "MoreModel.h"
#import "MJExtension.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //模型转字典
    model *mod1 = [[model alloc]init];
    mod1.str1 = @"1";
    mod1.str2 = @"2";
    mod1.arr = @[@1,@2,@3,@4,@5];
    mod1.dic = @{@"3":@[@3,@4]};
    
    NSDictionary*dic = [mod1 mj_keyValues];
    NSLog(@"%@",dic);
    
    
    
    [self single];
    [self more];
    
}
// //字典转模型  mode是一个
-(void)single{
   
    NSDictionary *dict = @{
                           @"statuses" : @[
                                   @{
                                       @"text" : @"Nice weather!",
                                       @"user" : @{
                                               @"name" : @"Rose",
                                               @"icon" : @"nami.png"
                                               }
                                       },
                                   @{
                                       @"text" : @"Go camping tomorrow!",
                                       @"user" : @{
                                               @"name" : @"Jack",
                                               @"icon" : @"lufy.png"
                                               }
                                       }
                                   ],
                           @"ads" : @[
                                   @{
                                       @"image" : @"ad01.png",
                                       @"url" : @"http://www.ad01.com"
                                       },
                                   @{
                                       @"image" : @"ad02.png",
                                       @"url" : @"http://www.ad02.com"
                                       }
                                   ],
                           @"totalNumber" : @"2014"
                           };
    //字典-》模型
    resoponsMode *resopnsM = [resoponsMode mj_objectWithKeyValues:dict];
    //字典数组-》模型数组
    //NSMutableArray 和NSArray都行
    NSMutableArray *userArray = [resoponsMode mj_objectArrayWithKeyValuesArray:resopnsM.statuses];
    resoponsMode *resopnsM2 =  userArray[0];
    
    NSLog(@"------------%@----%@--%@",resopnsM.totalNumber,resopnsM2.text,resopnsM2.user);
    //
    resoponsMode *resopnsM3 = [resoponsMode mj_objectWithKeyValues:resopnsM2.user];
    NSLog(@"------------%@",resopnsM3.name);
}
//字典转模型 返回多个mode
-(void)more{
    NSDictionary *dict = @{
                           @"statuses" : @[
                                   @{
                                       @"text" : @"Nice weather!",
                                       @"user" : @[
                                                     @{
                                                       @"name" : @"Rose",
                                                       @"icon" : @"nami.png"
                                                       },
                                                     @{
                                                         @"name" : @"2RoseSecond",
                                                         @"icon" : @"2Secondnami.png"
                                                         }
                                                   ]
                                       },
                                   @{
                                       @"text" : @"Go camping tomorrow!",
                                       @"user" : @[
                                               @{
                                                   @"name" : @"3Rose",
                                                   @"icon" : @"3nami.png"
                                                   },
                                               @{
                                                   @"name" : @"4RoseSecond",
                                                   @"icon" : @"4Secondnami.png"
                                                   }
                                               ]
                                       }
                                   ],
                           @"ads" : @[
                                   @{
                                       @"image" : @"ad01.png",
                                       @"url" : @"http://www.ad01.com"
                                       },
                                   @{
                                       @"image" : @"ad02.png",
                                       @"url" : @"http://www.ad02.com"
                                       }
                                   ],
                           @"totalNumber" : @"2014"
                           };
    //字典-》模型
    MoreModel *MoreResopnsM = [MoreModel mj_objectWithKeyValues:dict];
    //字典数组-》模型数组
    //NSMutableArray 和NSArray都行

    NSMutableArray *userArray = [SecondModel mj_objectArrayWithKeyValuesArray:MoreResopnsM.statuses];
    SecondModel *secondModel =  userArray[0];
    NSLog(@"------------%@----%@--%@",MoreResopnsM.totalNumber,secondModel.text,secondModel.user);
    
    NSArray *userArray2 = [ThreeModel mj_objectArrayWithKeyValuesArray:secondModel.user];
    ThreeModel *threeModel =  userArray2[0];
    NSLog(@"------------%@",threeModel.name);

}


@end
